﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace Mbs.Windows
{
    /// <summary>
    /// UserControl 视图基类
    /// </summary>
    public partial class UserControlView : UserControl,IView
    {
        /// <summary>
        /// 可回收资源列表
        /// </summary>
        public ICompositeDisposableObject Disposes { get; private set; }

        public UserControlView()
        {
            IsSupportGlobalization = true;
            Disposes = new CompositeDisposableObject();
        }

        /// <summary>
        /// 初始化视图
        /// </summary>
        public virtual void Init() { }

        /// <summary>
        /// 把视图上的UI元素上的相关事件附加到消息总线上
        /// </summary>
        /// <returns></returns>
        public virtual IEnumerator<IDisposable> Attach()
        {
            yield break;
        }

        /// <summary>
        /// 订阅消息总线发过来的消息
        /// </summary>
        /// <returns></returns>
        public virtual IEnumerator<IDisposable> Subscribe()
        {
            yield break;
        }

        /// <summary>
        /// 释放资源
        /// </summary>
        /// <param name="disposing"></param>
        protected override void Dispose(bool disposing)
        {
            Disposes.Dispose();
            base.Dispose(disposing);
        }

        /// <summary>
        /// 是否支持国际化
        /// </summary>
        public bool IsSupportGlobalization { get; set; }

        /// <summary>
        /// 初始化国际化资源
        /// </summary>
        public virtual void InitializeResource()
        {
        }

        /// <summary>
        /// 刷新国际化资源
        /// </summary>
        public virtual void RefreshResource()
        {
            if(IsSupportGlobalization)
                InitializeResource();
        }

       
    }
}